package com.kfm.base.thread.day01;

public class Demo08 {

    public static void main(String[] args) {
        Runnable r = () -> {
            Thread thread = Thread.currentThread();
//            for (int i = 0; i < 10; i++) {
//                if (i == 3){
////                    thread.stop(); // 停止线程
//                    thread.interrupt(); // 中断线程， 标记线程中断状态
//                }
//                System.out.println(Thread.interrupted());
//            }
            int count = 0;

            while(!Thread.interrupted()){ // thread.isInterrupted()
//                if (count == 5){
//                    thread.interrupt(); // 我想停
//                }
                System.out.println("执行" + count ++);
            }
        };

        Thread thread = new Thread(r);

        thread.start();

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        thread.interrupt();

    }
}
